#!/usr/bin/python

import sys
import math
import getopt

import acgt2wyk

def usage():
    print '''Usage : angle.py [options] [files]

    Options:
    --------
    -h, --help                   Display this text and exit.

    There should be two files having data points, between whom
    we are trying to find angles. There are two types of file
    formats are supported. In first form, file might contain a
    matrix in WYK form. In other form file might contain a
    DNA sequence. If none of the files is in DNA sequence form
    angle will be calculated between given WYK matrices. If any
    of the file contains a DNA sequence, it will be first
    converted to WYK form and then later angle will be calculated.
    '''

def vectorLength(vec):
    w = 0

    for e in vec:
        w += float(e) * float(e)

    w = math.sqrt(w)

    return w

def dotProduct(vec1, vec2):
    assert(vectorLength(vec1) != 0)
    assert(vectorLength(vec2) != 0)

    assert(len(vec1) == len(vec2))

    ans = 0

    for k in xrange(len(vec1)):
        ans += float(vec1[k]) * float(vec2[k])

    return ans

def main(argv):
    try:
        opts, args = getopt.getopt(argv, "h", ["help"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        else:
            pass

    if (len(args) != 2):
        usage()
        sys.exit("You should provide just two files having matrices")


    # for 1st matrix
    file1 = open(args[0])
    lines = file1.readlines()

    vec1 = []

    total_lines = 0

    for line in lines:
        cleanline = (line).strip()
        if len(cleanline) != 0:
            total_lines += 1
            vec1 += cleanline.split(" ")
        else:
            pass

    if total_lines == 1:
        temp = acgt2wyk.seq2wyk(lines[0].strip())
        vec1 = []

        for l in temp:
            vec1 += l
    else:
        pass
    
    # now for 2nd matrix
    file2 = open(args[1])
    
    lines = file2.readlines()

    vec2 = []

    total_lines = 0

    for line in lines:
        cleanline = (line).strip()

        if len(cleanline) != 0:
            total_lines += 1
            vec2 += cleanline.split(" ")
        else:
            pass

    if total_lines == 1:
        temp = acgt2wyk.seq2wyk(lines[0].strip())
        vec2 = []

        for l in temp:
            vec2 += l
    else:
        pass

    if (vectorLength(vec1) == 0) or (vectorLength(vec2) == 0):
        sys.exit("Vector lengths are unequal. It should not happen.")

    angle = dotProduct(vec1, vec2)/(vectorLength(vec1)*vectorLength(vec2))

    return (math.acos(round(angle, 3))) * 180 / math.pi

if __name__ == "__main__":
    res = main(sys.argv[1:])

    print '%.2f' % (res)

